//
//  UEXController.m
//  weizhuan
//
//  Created by lixun on 13-8-1.
//  Copyright (c) 2013年 lixun. All rights reserved.
//

#import "UEXController.h"
#import "AppUtility.h"
#import "NetHttp.h"
#import "AHAlertView.h"
#import "AppDelegate.h"
@interface UEXController (){
    UIImageView *navigationImageView;
    
}

@end

@implementation UEXController


@synthesize delegate = _delegate;

#pragma mark -
#pragma mark lifeCircle
#pragma mark -
- (void)dealloc {
	//for view
	[_nullView release];
	[_indicatorView release];
    
	//for data
    [super dealloc];
}

- (void)viewDidUnload {
	[super viewDidUnload];
	//for view
	[_nullView release];
	_nullView = nil;
	[_indicatorView release];
	_indicatorView = nil;
	//for data
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self applyCustomAlertAppearance];
    self.view.backgroundColor = BACKCOLOR;
    
    navigationImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];

    
//    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

    
    UIColor * cc = [UIColor whiteColor];
    
    
    NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:18.0],UITextAttributeFont,cc,UITextAttributeTextColor,nil];
    self.navigationController.navigationBar.titleTextAttributes = dict;

    
    if ([AppUtility isIOS7]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
        self.navigationController.interactivePopGestureRecognizer.delegate =(id)self;
    }
    else
    {
        UISwipeGestureRecognizer *recognizer;
        
        recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom)];
        
        [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
        
        [[self view] addGestureRecognizer:recognizer];
        
        [recognizer release];
    }
    
    self.navigationController.navigationBar.backgroundColor = TITLECOLOR;
     self.navigationController.navigationBar.translucent = NO;

    
    if ([AppUtility isIOS10]) {
        
        self.navigationController.navigationBar.barTintColor = BLUECOLOR;
        
        self.edgesForExtendedLayout = UIRectEdgeNone;
        NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                                   [UIColor whiteColor],UITextAttributeTextColor,
                                                   [UIColor whiteColor],UITextAttributeTextShadowColor,
                                                   [NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset,[UIFont systemFontOfSize:18],UITextAttributeFont,nil];
        
        [[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
        //返回变白色
        [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
        
    }

}
- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
        return (UIImageView *)view;
    }
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    return nil;
}
#pragma mark - UINavigationControllerDelegate
// 将要显示控制器
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自己
    BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
    
    [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}
-(void)handleSwipeFrom
{
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];

    navigationImageView.hidden = YES;
//    self.navigationController.delegate = self;
}

- (void)viewWillDisappear:(BOOL)animated {
	[super viewWillDisappear:animated];


}

- (void)viewDidAppear:(BOOL)animated {
	[super viewDidAppear:animated];

    
}

- (void)viewDidDisappear:(BOOL)animated {
	[super viewDidDisappear:animated];
}

// for views
#pragma mark -
#pragma mark for views
#pragma mark -
- (void)initNavBtns {
    self.navigationController.navigationBar.hidden = YES;
}

- (void)initViews {
	if (_viewInitDone) {
		return;
	}
	_viewInitDone = YES;

}

- (void)applyCustomAlertAppearance
{
	[[AHAlertView appearance] setContentInsets:UIEdgeInsetsMake(12, 18, 12, 18)];
	
	[[AHAlertView appearance] setBackgroundImage:[UIImage imageNamed:@"AHBJ"]];
	
	UIEdgeInsets buttonEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 8);
	[[AHAlertView appearance] setCancelButtonBackgroundImage:[[UIImage imageNamed:@"btn_image"] resizableImageWithCapInsets:buttonEdgeInsets]
													forState:UIControlStateNormal];
    
	[[AHAlertView appearance] setButtonBackgroundImage:[[UIImage imageNamed:@"btn_image"] resizableImageWithCapInsets:buttonEdgeInsets]
											  forState:UIControlStateNormal];
	
	[[AHAlertView appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
													  [UIFont boldSystemFontOfSize:18], UITextAttributeFont,
													  [UIColor whiteColor], UITextAttributeTextColor,
													  [UIColor blackColor], UITextAttributeTextShadowColor,
													  [NSValue valueWithCGSize:CGSizeMake(0, -1)], UITextAttributeTextShadowOffset,
													  nil]];
	
	[[AHAlertView appearance] setMessageTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
														[UIFont systemFontOfSize:14], UITextAttributeFont,
														[UIColor colorWithWhite:0.8 alpha:1.0], UITextAttributeTextColor,
														[UIColor blackColor], UITextAttributeTextShadowColor,
														[NSValue valueWithCGSize:CGSizeMake(0, -1)], UITextAttributeTextShadowOffset,
														nil]];
	
	[[AHAlertView appearance] setButtonTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
															[UIFont boldSystemFontOfSize:16], UITextAttributeFont,
															[UIColor whiteColor], UITextAttributeTextColor,
															[UIColor clearColor], UITextAttributeTextShadowColor,
															[NSValue valueWithCGSize:CGSizeMake(0, -1)], UITextAttributeTextShadowOffset,
															nil]];
}


- (void)showNullView:(BOOL)show_ {
	/*if (!_nullView) {
		_nullView = [[NoDataView alloc] initWithFrame:CGRectMake(0, 0, 320, 416) text:@"暂无数据"];
		[self.view addSubview:_nullView];
	}
	_nullView.hidden = !show_;
	[self.view bringSubviewToFront:_nullView];*/
}

- (void)showIndicator:(BOOL)show_ {
	/*if (show_) {
		if (!_indicatorView) {
			_indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
			_indicatorView.frame = CGRectMake(150, 190, 20, 20);
			[_indicatorView startAnimating];
		}
		[self.view addSubview:_indicatorView];
	}
	else {
		[_indicatorView removeFromSuperview];
	}*/
}

- (void)haveNoData {
	//[self showNullView:YES];
	//[self showIndicator:NO];
}

#pragma mark -
#pragma mark for event
#pragma mark -
- (void)leftNavBtnClicked {
}

- (void)rightNavBtnClicked {
}

- (void)titleNavBtnClicked {
}

#pragma mark -
#pragma mark for data
#pragma mark -
- (void)initData {
}

- (void)cleanData {
}

#pragma mark -
#pragma mark for delegate
#pragma mark -
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return NO;//系统默认不支持旋转功能
}

-(BOOL)shouldAutorotate{
    return NO;
}
-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}
@end
